DROP TABLE IF EXISTS "feeds";
CREATE TABLE [feeds] (
[feed_id] INTEGER  PRIMARY KEY NOT NULL,
[folder_id] INTEGER DEFAULT 0 NOT NULL,
[xml_url] TEXT  UNIQUE NOT NULL,
[web_url] TEXT  NULL,
[title] TEXT  NULL,
[option_flags] TEXT  NULL,
[filter_flags] TEXT  NULL,
[update_interval] INTEGER DEFAULT 60 NULL,
[update_time] TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL,
[creation_time] TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL
);
DROP TABLE IF EXISTS "folders";
CREATE TABLE [folders] (
[folder_id] INTEGER  NOT NULL PRIMARY KEY,
[title] TEXT  NOT NULL
);
INSERT INTO "folders" VALUES(0,'Uncategorized');
DROP TABLE IF EXISTS "items";
CREATE TABLE [items] (
[item_id] INTEGER  PRIMARY KEY NOT NULL,
[feed_id] INTEGER  NOT NULL,
[url] TEXT  UNIQUE NOT NULL,
[title] TEXT  NULL,
[author] TEXT  NULL,
[content] BLOB  NULL,
[read_status] BOOLEAN DEFAULT FALSE NULL,
[published_time] TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL
);
DROP TABLE IF EXISTS "saved";
CREATE TABLE "saved" (
[item_id] INTEGER  PRIMARY KEY NOT NULL,
[feed_id] INTEGER  NOT NULL,
[url] TEXT  UNIQUE NOT NULL,
[title] TEXT  NULL,
[author] TEXT  NULL,
[content] BLOB  NULL,
[read_status] BOOLEAN DEFAULT FALSE NULL,
[published_time] TIMESTAMP DEFAULT CURRENT_TIMESTAMP NULL
);
CREATE TRIGGER "OnDeleteFeed" AFTER DELETE ON feeds BEGIN DELETE FROM items WHERE items.feed_id = OLD.feed_id; END;
CREATE TRIGGER "OnDeleteFolder" AFTER DELETE ON folders BEGIN DELETE FROM feeds WHERE feeds.folder_id = OLD.folder_id; END;
